import {type App} from "vue";
import {message} from "ant-design-vue";
import {Message as CoreMessage} from '@idmy/core'
import {isString} from "lodash-es";

export interface MessageProps {
  content: any
  duration?: number
  onClose?: () => void
}

const install = (app: App) => {
  CoreMessage.success = (props: string | MessageProps) => {
    if (isString(props)) {
      return message.success(props)
    } else {
      return message.success(props.content, props.duration, props.onClose)
    }
  }
  CoreMessage.error = (props: string | MessageProps) => {
    if (isString(props)) {
      return message.error(props)
    } else {
      return message.error(props.content, props.duration, props.onClose)
    }
  }
  CoreMessage.warn = (props: string | MessageProps) => {
    if (isString(props)) {
      return message.warn(props)
    } else {
      return message.warn(props.content, props.duration, props.onClose)
    }
  }
  CoreMessage.info = (props: string | MessageProps) => {
    if (isString(props)) {
      return message.info(props)
    } else {
      return message.info(props.content, props.duration, props.onClose)
    }
  }
  CoreMessage.loading = (props: string | MessageProps) => {
    if (isString(props)) {
      return message.loading(props)
    } else {
      return message.loading(props.content, props.duration, props.onClose)
    }
  }
}

export default {
  install
}
